package com.d6game.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.d6game.web.entity.User;
import com.d6game.web.service.UserService;

@Controller
@RequestMapping(value = "/me")
public class MeController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(CommonController.class);  
	@Autowired
	UserService userService;
	
	@RequestMapping(value="/{uid}")
	public ModelAndView home(@PathVariable("uid") String uid,HttpServletRequest request, HttpServletResponse response, HttpSession session){
		User user = (User) session.getAttribute("user");
		String view = request.getParameter("view");
		if(user != null && user.getUid().toString().equals(uid)){
			if(user.getRole().equals("0")){
				if(view == null || view.equals("") || view.equals("generate_activation_code")){
					return new ModelAndView("/purchase/admin/generate_activation_code");
				}
			}else {
				return new ModelAndView(new RedirectView("/weibo/home"));
			}
		}
		return new ModelAndView(new RedirectView("/"));
	}
}
